// set(不可重复)和multiset(可重复)
// 插入时会自动排序
#include <iostream>
#include <set>
using namespace std;
void test1()
{
    set<int> s;
    // 插入数据只有insert
    s.insert(38);
    s.insert(29);
    s.insert(31);
    for (set<int>::iterator it = s.begin(); it != s.end(); ++it)
    {
        cout << *it << endl;
    }
    if (s.find(38) == s.end())
    {
        cout << "没找到" << endl;
    }
    else
    {
        cout << "找到了" << endl;
    }
    cout << s.count(31) << endl;
    multiset<int> s1;
    s1.insert(8);
    s1.insert(8);
    cout << s1.count(8) << endl;
    // set执行insert返回pair
    pair<set<int>::iterator, bool> ret1 = s.insert(31);
    cout << ret1.second << endl;
    pair<set<int>::iterator, bool> ret2 = s.insert(32);
    cout << ret2.second << endl;
}
// 改变set的默认排序方式(仿函数)
// 对于自定义数据类型，必须指定排序方式
class MyCompare
{
public:
    bool operator()(int a, int b)
    {
        return a > b;
    }
};
void test2()
{
    set<int, MyCompare> s3;
    for (int i = 1; i < 50; i += 10)
    {
        s3.insert(i);
    }
    for (set<int, MyCompare>::iterator it = s3.begin(); it != s3.end(); ++it)
    {
        cout << *it << endl;
    }
}
int main(void)
{
    // test1();
    test2();

    return 0;
}